package com.right.health.app.ui.advisory;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.google.zxing.util.Constant;
import com.magic.basic.activity.BaseActivity;
import com.magic.basic.utils.PermissionUtil;
import com.magic.basic.utils.ToastUtil;
import com.right.health.app.R;
import com.right.health.app.ui.common.Capture2Activity;

/*
 * Created by hopeliao on 2019-10-10
 *  二维码添加医生
 */
public class FindDoctorByQrcodeActivity extends BaseActivity {

    private static final int REQUEST_CODE_QRCODE = 1;

    @Override
    public void onCreate(Bundle bundle, String s) {
        setContentView(R.layout.find_doctor_by_qrcode);
    }

    @Override
    public void findView() {
        findViewById(R.id.ib_qrcode).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PermissionUtil.with(FindDoctorByQrcodeActivity.this)
                        .listener(new PermissionUtil.RequestPermissionListener() {
                            @Override
                            public void onResult(boolean succ, int requestCode) {
                                if (succ) {
                                    startActivityForResult(Capture2Activity.class, REQUEST_CODE_QRCODE);
                                }
                            }
                        }).request(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.CAMERA);
            }
        });
    }

    @Override
    public void initialize() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(RESULT_OK == resultCode) {
            if(requestCode == REQUEST_CODE_QRCODE) {
                Bundle bundle = data.getExtras();
                if(bundle != null && bundle.containsKey(Constant.INTENT_EXTRA_KEY_QR_SCAN)) {
                   String text =  bundle.getString(Constant.INTENT_EXTRA_KEY_QR_SCAN);
                    ToastUtil.show(this, text);
                }
            }
        }
    }
}
